package main

import (
	"fmt"
)

func main() {
	name := "root"
	passwd := "123456"
	balance := 1000
	count := 3
	flag := 0
	var choose string
	fmt.Println("你好，请输入您的用户名和密码：")
	for count > 0 {
		if flag == 0 {
			fmt.Scan(&name, &passwd) //定义标志，避免重复输入（花了我好久解决这个问题。。。）
		}
		if name == "root" && passwd == "123456" {
			fmt.Println("登陆成功！")
			flag = 1
		}
		if flag == 1 {
			fmt.Println("您要办理哪些业务？\n 存钱请按1\n 取钱请按2\n 查询余额请按3\n 退出系统请按q\n")
			fmt.Scan(&choose)
			if choose == "1" {
				fmt.Println("请输入您要存取的金额(数字)：")
				var num int
				fmt.Scan(&num)
				if Save_money(num) {
					balance = balance + num
					fmt.Println("存入成功!您的账户目前有", balance, "元")
				} else {
					fmt.Println("您已取消操作")
				}
			} else if choose == "2" {
				fmt.Println("请输入您要取出的金额(数字)：")
				var num int
				fmt.Scan(&num)
				if Draw_money(num, balance) {
					balance = balance - num
					fmt.Println("成功取出!您的账户目前有", balance, "元")
				} else {
					fmt.Println("您账户没有那么多钱，请重新操作")
				}
			} else if choose == "3" {
				fmt.Println("您的余额为：", balance, "元")
			} else if choose == "q" {
				fmt.Println("您已退出系统")
				count = 0
				break
			}
		} else {
			fmt.Println("登陆失败，请重试.您还有", count-1, "次机会")
			count = count - 1
		}
	}
	fmt.Println("您将被强制退出！")

}

func Save_money(num int) bool {
	fmt.Println("确定存入", num, "元吗？\n请输入是/否")
	var decide string
	fmt.Scan(&decide)
	if decide == "是" {
		return true
	} else {
		return false
	}

}

func Draw_money(num, balance int) bool {
	fmt.Println("确定取出", num, "元吗？\n请输入是/否")
	var decide string
	fmt.Scan(&decide)
	if num <= balance && decide == "是" {
		return true
	} else if decide == "否" {
		fmt.Println("您已取消操作")
		return false
	} else {
		return false
	}
}
